{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 提取xsd文件坐标并操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vaspy.matstudio import XsdFile"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "xsd = XsdFile('h_top_c_fcc_far.xsd')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 显示坐标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.2972892 ,  0.15463501,  0.43569139],\n",
       "       [ 0.73186612,  0.37097034,  0.41434976],\n",
       "       [ 0.48259474,  0.25402011,  0.47432829],\n",
       "       [ 0.07330592,  0.05287656,  0.01079317],\n",
       "       [ 0.07330592,  0.55287657,  0.01079317],\n",
       "       [ 0.57330592,  0.05287656,  0.01079317],\n",
       "       [ 0.57330592,  0.55287656,  0.01079317],\n",
       "       [ 0.73997259,  0.3862099 ,  0.12308022],\n",
       "       [ 0.73997259,  0.8862099 ,  0.12308022],\n",
       "       [ 0.23997259,  0.3862099 ,  0.12308022],\n",
       "       [ 0.23997259,  0.8862099 ,  0.12308022],\n",
       "       [ 0.40899389,  0.21427639,  0.23349414],\n",
       "       [ 0.91185849,  0.71681419,  0.2345969 ],\n",
       "       [ 0.91211185,  0.21548399,  0.23483813],\n",
       "       [ 0.40209504,  0.71118551,  0.23451221],\n",
       "       [ 0.09123061,  0.04977886,  0.35005352],\n",
       "       [ 0.58588392,  0.55240731,  0.34386542],\n",
       "       [ 0.08125505,  0.54466019,  0.35622431],\n",
       "       [ 0.58650079,  0.04224914,  0.344275  ]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xsd.data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.3072892 ,  0.16463501,  0.44569139],\n",
       "       [ 0.74186612,  0.38097034,  0.42434976],\n",
       "       [ 0.49259474,  0.26402011,  0.48432829],\n",
       "       [ 0.08330592,  0.06287656,  0.02079317],\n",
       "       [ 0.08330592,  0.56287657,  0.02079317],\n",
       "       [ 0.58330592,  0.06287656,  0.02079317],\n",
       "       [ 0.58330592,  0.56287656,  0.02079317],\n",
       "       [ 0.74997259,  0.3962099 ,  0.13308022],\n",
       "       [ 0.74997259,  0.8962099 ,  0.13308022],\n",
       "       [ 0.24997259,  0.3962099 ,  0.13308022],\n",
       "       [ 0.24997259,  0.8962099 ,  0.13308022],\n",
       "       [ 0.41899389,  0.22427639,  0.24349414],\n",
       "       [ 0.92185849,  0.72681419,  0.2445969 ],\n",
       "       [ 0.92211185,  0.22548399,  0.24483813],\n",
       "       [ 0.41209504,  0.72118551,  0.24451221],\n",
       "       [ 0.10123061,  0.05977886,  0.36005352],\n",
       "       [ 0.59588392,  0.56240731,  0.35386542],\n",
       "       [ 0.09125505,  0.55466019,  0.36622431],\n",
       "       [ 0.59650079,  0.05224914,  0.354275  ]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xsd.data + 0.01"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 每个坐标数值增加0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "xsd.data += 0.01"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.3072892 ,  0.16463501,  0.44569139],\n",
       "       [ 0.74186612,  0.38097034,  0.42434976],\n",
       "       [ 0.49259474,  0.26402011,  0.48432829],\n",
       "       [ 0.08330592,  0.06287656,  0.02079317],\n",
       "       [ 0.08330592,  0.56287657,  0.02079317],\n",
       "       [ 0.58330592,  0.06287656,  0.02079317],\n",
       "       [ 0.58330592,  0.56287656,  0.02079317],\n",
       "       [ 0.74997259,  0.3962099 ,  0.13308022],\n",
       "       [ 0.74997259,  0.8962099 ,  0.13308022],\n",
       "       [ 0.24997259,  0.3962099 ,  0.13308022],\n",
       "       [ 0.24997259,  0.8962099 ,  0.13308022],\n",
       "       [ 0.41899389,  0.22427639,  0.24349414],\n",
       "       [ 0.92185849,  0.72681419,  0.2445969 ],\n",
       "       [ 0.92211185,  0.22548399,  0.24483813],\n",
       "       [ 0.41209504,  0.72118551,  0.24451221],\n",
       "       [ 0.10123061,  0.05977886,  0.36005352],\n",
       "       [ 0.59588392,  0.56240731,  0.35386542],\n",
       "       [ 0.09125505,  0.55466019,  0.36622431],\n",
       "       [ 0.59650079,  0.05224914,  0.354275  ]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xsd.data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 重新生成新的xsd文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "xsd.tofile('new.xsd')  # 当前路径下会生成新的xsd文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "00-04.arc                   POSCAR\r\n",
      "00-04.xtd                   POSCAR_freq\r\n",
      "CONTCAR                     POTCAR\r\n",
      "DOS_SUM                     Untitled.ipynb\r\n",
      "ELFCAR                      XDATCAR\r\n",
      "INCAR                       bulk.xsd\r\n",
      "INCAR2                      ceo2-111.cif\r\n",
      "KPOINTS                     fort.188\r\n",
      "OSZICAR                     h_top_c_fcc_far.xsd\r\n",
      "OSZICAR_md                  h_top_c_fcc_far_noname.xsd\r\n",
      "OUT.ANI                     new.xsd\r\n",
      "OUTCAR                      ts.xyz\r\n",
      "OUTCAR_freq                 vasp.script\r\n",
      "PLOTCON\r\n"
     ]
    }
   ],
   "source": [
    "ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 笛卡尔坐标和分数坐标的相互转换"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[  4.31035158,  -2.48858265,   0.        ],\n",
       "       [  0.        ,   4.97716529,   0.        ],\n",
       "       [  0.        ,   0.        ,  18.09575766]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xsd.bases"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [],
   "source": [
    "cart = xsd.dir2cart(xsd.bases, xsd.data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.32452449,  0.05470107,  8.0651234 ],\n",
       "       [ 3.19770379,  0.04995723,  7.67893041],\n",
       "       [ 2.12325651,  0.08820902,  8.76428743],\n",
       "       [ 0.35907782,  0.10563338,  0.37626824],\n",
       "       [ 0.35907782,  2.59421603,  0.37626824],\n",
       "       [ 2.51425361, -1.13865795,  0.37626824],\n",
       "       [ 2.51425361,  1.3499247 ,  0.37626824],\n",
       "       [ 3.23264554,  0.10563338,  2.40818746],\n",
       "       [ 3.23264554,  2.59421602,  2.40818746],\n",
       "       [ 1.07746975,  1.3499247 ,  2.40818746],\n",
       "       [ 1.07746975,  3.83850735,  2.40818746],\n",
       "       [ 1.80601096,  0.07355977,  4.40621097],\n",
       "       [ 3.97353422,  1.3233533 ,  4.42616618],\n",
       "       [ 3.97462628, -1.17248048,  4.43053138],\n",
       "       [ 1.77627452,  2.56392691,  4.4246337 ],\n",
       "       [ 0.43633953,  0.0456085 ,  6.51544117],\n",
       "       [ 2.5684692 ,  1.31628775,  6.40346289],\n",
       "       [ 0.39334134,  2.53353974,  6.62710637],\n",
       "       [ 2.57112813, -1.22438893,  6.41087462]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cart"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "cart += 0.001  # 在笛卡尔坐标基础上都增加0.001"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.32552449,  0.05570107,  8.0661234 ],\n",
       "       [ 3.19870379,  0.05095723,  7.67993041],\n",
       "       [ 2.12425651,  0.08920902,  8.76528743],\n",
       "       [ 0.36007782,  0.10663338,  0.37726824],\n",
       "       [ 0.36007782,  2.59521603,  0.37726824],\n",
       "       [ 2.51525361, -1.13765795,  0.37726824],\n",
       "       [ 2.51525361,  1.3509247 ,  0.37726824],\n",
       "       [ 3.23364554,  0.10663338,  2.40918746],\n",
       "       [ 3.23364554,  2.59521602,  2.40918746],\n",
       "       [ 1.07846975,  1.3509247 ,  2.40918746],\n",
       "       [ 1.07846975,  3.83950735,  2.40918746],\n",
       "       [ 1.80701096,  0.07455977,  4.40721097],\n",
       "       [ 3.97453422,  1.3243533 ,  4.42716618],\n",
       "       [ 3.97562628, -1.17148048,  4.43153138],\n",
       "       [ 1.77727452,  2.56492691,  4.4256337 ],\n",
       "       [ 0.43733953,  0.0466085 ,  6.51644117],\n",
       "       [ 2.5694692 ,  1.31728775,  6.40446289],\n",
       "       [ 0.39434134,  2.53453974,  6.62810637],\n",
       "       [ 2.57212813, -1.22338893,  6.41187462]])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cart"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 转换回分数坐标"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "xsd.data = xsd.cart2dir(xsd.bases, cart)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.3075212 ,  0.16495193,  0.44574665],\n",
       "       [ 0.74209812,  0.38128726,  0.42440502],\n",
       "       [ 0.49282674,  0.26433703,  0.48438356],\n",
       "       [ 0.08353792,  0.06319348,  0.02084844],\n",
       "       [ 0.08353792,  0.56319348,  0.02084844],\n",
       "       [ 0.58353792,  0.06319348,  0.02084844],\n",
       "       [ 0.58353792,  0.56319348,  0.02084844],\n",
       "       [ 0.75020459,  0.39652682,  0.13313548],\n",
       "       [ 0.75020459,  0.89652681,  0.13313548],\n",
       "       [ 0.25020459,  0.39652681,  0.13313548],\n",
       "       [ 0.25020459,  0.89652682,  0.13313548],\n",
       "       [ 0.41922589,  0.22459331,  0.2435494 ],\n",
       "       [ 0.92209049,  0.72713111,  0.24465216],\n",
       "       [ 0.92234385,  0.22580091,  0.24489339],\n",
       "       [ 0.41232704,  0.72150243,  0.24456747],\n",
       "       [ 0.10146261,  0.06009577,  0.36010878],\n",
       "       [ 0.59611592,  0.56272423,  0.35392068],\n",
       "       [ 0.09148705,  0.55497711,  0.36627957],\n",
       "       [ 0.59673279,  0.05256606,  0.35433027]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "xsd.data"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
